﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Threading;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows.Threading;
using University.Workshop.Model;
using University.Workshop.DataAccess;
namespace University.Workshop.ClientApp
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class Good : Window
    {
        Luck luck = new Luck();
        int UpPosition = 1;
        int DownPosition = 1;
        bool MyVerify = true;
        int PlayUp = 0;
        int PlayDown = 0;
        bool[] colors = new bool[7];
        Client client = new Client();
        User user;
        bool end = false;
        public bool Banned = false;
        bool onlyOneMessage = false;
        public Good()
        {
            InitializeComponent();
        }

        public Good(User user)
        {
            InitializeComponent();
            this.user = user;
           
        }
        

        private void image1_MouseEnter(object sender, MouseEventArgs e)
        {
            if (DownPosition < 2 || UpPosition < 2)
            {
                border1.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
                border8.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
            }
            else
            {
                if (colors[0])
                {
                    border1.Background = Brushes.Green;
                    border8.Background = Brushes.Green;
                }
                else
                {
                    border1.Background = Brushes.Red;
                    border8.Background = Brushes.Red;
                }
            }
        }

        private void image1_MouseLeave(object sender, MouseEventArgs e)
        {
            if (DownPosition < 2 || UpPosition < 2)
            {
                border1.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
                border8.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
            }
            else
            {
                if (colors[0])
                {
                    border1.Background = Brushes.Green;
                    border8.Background = Brushes.Green;
                }
                else
                {
                    border1.Background = Brushes.Red;
                    border8.Background = Brushes.Red;
                }
            }
            
        }

        private void image2_MouseEnter(object sender, MouseEventArgs e)
        {
            
            if (DownPosition < 4 || UpPosition < 4)
            {
                border2.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
                border9.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
            }
            else
            {
                if (colors[1])
                {
                    border2.Background = Brushes.Green;
                    border9.Background = Brushes.Green;
                }
                else
                {
                    border2.Background = Brushes.Red;
                    border9.Background = Brushes.Red;
                }
            }
        }

        private void image2_MouseLeave(object sender, MouseEventArgs e)
        {
           
            if (DownPosition < 4 || UpPosition < 4)
            {
                border2.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SteelBlue, 90);
                border9.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SteelBlue, 90);
            }
            else
            {
                if (colors[1])
                {
                    border2.Background = Brushes.Green;
                    border9.Background = Brushes.Green;
                }
                else
                {
                    border2.Background = Brushes.Red;
                    border9.Background = Brushes.Red;
                }
            }

        }

        private void image3_MouseEnter(object sender, MouseEventArgs e)
        {
           
            if (DownPosition < 6 || UpPosition < 6)
            {
                border3.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
                border10.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
            }
            else
            {
                if (colors[2])
                {
                    border10.Background = Brushes.Green;
                    border3.Background = Brushes.Green;
                }
                else
                {
                    border10.Background = Brushes.Red;
                    border3.Background = Brushes.Red;
                }
            }
        }

        private void image3_MouseLeave(object sender, MouseEventArgs e)
        {
           
            if (DownPosition < 6 || UpPosition < 6)
            {
                border3.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
                border10.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
            }
            else
            {
                if (colors[2])
                {
                    border10.Background = Brushes.Green;
                    border3.Background = Brushes.Green;
                }
                else
                {
                    border10.Background = Brushes.Red;
                    border3.Background = Brushes.Red;
                }
            }
        }

        private void image4_MouseEnter(object sender, MouseEventArgs e)
        {
           
            if (DownPosition < 8 || UpPosition < 8)
            {
                border4.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
                border11.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
            }
            else
            {
                if (colors[3])
                {
                    border11.Background = Brushes.Green;
                    border4.Background = Brushes.Green;
                }
                else
                {
                    border11.Background = Brushes.Red;
                    border4.Background = Brushes.Red;
                }
            }
        }

        private void image4_MouseLeave(object sender, MouseEventArgs e)
        {
            
            if (DownPosition < 8 || UpPosition < 8)
            {
                border4.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
                border11.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
            }
            else
            {
                if (colors[3])
                {
                    border11.Background = Brushes.Green;
                    border4.Background = Brushes.Green;
                }
                else
                {
                    border11.Background = Brushes.Red;
                    border4.Background = Brushes.Red;
                }
            }
        }

        private void image5_MouseEnter(object sender, MouseEventArgs e)
        {
            
            if (DownPosition < 10 || UpPosition < 10)
            {
                border5.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
                border12.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
            }
            else
            {
                if (colors[4])
                {
                    border12.Background = Brushes.Green;
                    border5.Background = Brushes.Green;
                }
                else
                {
                    border12.Background = Brushes.Red;
                    border5.Background = Brushes.Red;
                }
            }
        }

        private void image5_MouseLeave(object sender, MouseEventArgs e)
        {
            
            if (DownPosition < 10 || UpPosition < 10)
            {
                border5.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
                border12.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
            }
            else
            {
                if (colors[4])
                {
                    border12.Background = Brushes.Green;
                    border5.Background = Brushes.Green;
                }
                else
                {
                    border12.Background = Brushes.Red;
                    border5.Background = Brushes.Red;
                }
            }
        }

        private void image6_MouseEnter(object sender, MouseEventArgs e)
        {
           
            if (DownPosition < 12 || UpPosition < 12)
            {
                border6.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
                border13.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
            }
            else
            {
                if (colors[5])
                {
                    border13.Background = Brushes.Green;
                    border6.Background = Brushes.Green;
                }
                else
                {
                    border13.Background = Brushes.Red;
                    border6.Background = Brushes.Red;
                }
            }
        }

        private void image6_MouseLeave(object sender, MouseEventArgs e)
        {
           
            if (DownPosition < 12 || UpPosition < 12)
            {
                border6.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
                border13.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
            }
            else
            {
                if (colors[5])
                {
                    border13.Background = Brushes.Green;
                    border6.Background = Brushes.Green;
                }
                else
                {
                    border13.Background = Brushes.Red;
                    border6.Background = Brushes.Red;
                }
            }
        }

        private void image7_MouseEnter(object sender, MouseEventArgs e)
        {
           
            if (DownPosition < 14 || UpPosition < 14)
            {
                border7.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
                border14.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
            }
            else
            {
                if (colors[6])
                {
                    border14.Background = Brushes.Green;
                    border7.Background = Brushes.Green;
                }
                else
                {
                    border14.Background = Brushes.Red;
                    border7.Background = Brushes.Red;
                }
            }
        }

        private void image7_MouseLeave(object sender, MouseEventArgs e)
        {
            
            if (DownPosition < 14 || UpPosition < 14)
            {
                border7.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
                border14.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
            }
            else
            {
                if (colors[6])
                {
                    border14.Background = Brushes.Green;
                    border7.Background = Brushes.Green;
                }
                else
                {
                    border14.Background = Brushes.Red;
                    border7.Background = Brushes.Red;
                }
            }
        }

        private void image8_MouseEnter(object sender, MouseEventArgs e)
        {
           
            if (DownPosition < 2 || UpPosition < 2)
            {
                border8.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
                border1.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
            }
            else
            {
                if (colors[0])
                {
                    border1.Background = Brushes.Green;
                    border8.Background = Brushes.Green;
                }
                else
                {
                    border1.Background = Brushes.Red;
                    border8.Background = Brushes.Red;
                }
            }
        }

        private void image8_MouseLeave(object sender, MouseEventArgs e)
        {
           
            if (DownPosition < 2 || UpPosition < 2)
            {
                border8.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
                border1.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
            }
            else
            {
                if (colors[0])
                {
                    border1.Background = Brushes.Green;
                    border8.Background = Brushes.Green;
                }
                else
                {
                    border1.Background = Brushes.Red;
                    border8.Background = Brushes.Red;
                }
            }
        }

        private void image9_MouseEnter(object sender, MouseEventArgs e)
        {
           
            if (DownPosition < 4 || UpPosition < 4)
            {
                border9.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
                border2.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
            }
            else
            {
                if (colors[1])
                {
                    border2.Background = Brushes.Green;
                    border9.Background = Brushes.Green;
                }
                else
                {
                    border2.Background = Brushes.Red;
                    border9.Background = Brushes.Red;
                }
            }
        }

        private void image9_MouseLeave(object sender, MouseEventArgs e)
        {
           
            if (DownPosition < 4 || UpPosition < 4)
            {
                border9.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
                border2.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
            }
            else
            {
                if (colors[1])
                {
                    border2.Background = Brushes.Green;
                    border9.Background = Brushes.Green;
                }
                else
                {
                    border2.Background = Brushes.Red;
                    border9.Background = Brushes.Red;
                }
            }
        }

        private void image10_MouseEnter(object sender, MouseEventArgs e)
        {
           
            if (DownPosition < 6 || UpPosition < 6)
            {
                border10.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
                border3.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
            }
            else
            {
                if (colors[2])
                {
                    border10.Background = Brushes.Green;
                    border3.Background = Brushes.Green;
                }
                else
                {
                    border10.Background = Brushes.Red;
                    border3.Background = Brushes.Red;
                }
            }
        }

        private void image10_MouseLeave(object sender, MouseEventArgs e)
        {
           
            if (DownPosition < 6 || UpPosition < 6)
            {
                border10.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
                border3.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
            }
            else
            {
                if (colors[2])
                {
                    border10.Background = Brushes.Green;
                    border3.Background = Brushes.Green;
                }
                else
                {
                    border10.Background = Brushes.Red;
                    border3.Background = Brushes.Red;
                }
            }
        }

        private void image11_MouseEnter(object sender, MouseEventArgs e)
        {
           
            if (DownPosition < 8 || UpPosition < 8)
            {
                border11.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
                border4.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
            }
            else
            {
                if (colors[3])
                {
                    border11.Background = Brushes.Green;
                    border4.Background = Brushes.Green;
                }
                else
                {
                    border11.Background = Brushes.Red;
                    border4.Background = Brushes.Red;
                }
            }
        }

        private void image11_MouseLeave(object sender, MouseEventArgs e)
        {
            
            if (DownPosition < 8 || UpPosition < 8)
            {
                border11.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
                border4.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
            }
            else
            {
                if (colors[3])
                {
                    border11.Background = Brushes.Green;
                    border4.Background = Brushes.Green;
                }
                else
                {
                    border11.Background = Brushes.Red;
                    border4.Background = Brushes.Red;
                }
            }
        }

        private void image12_MouseEnter(object sender, MouseEventArgs e)
        {
            
            if (DownPosition < 10 || UpPosition < 10)
            {
                border12.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
                border5.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
            }
            else
            {
                if (colors[4])
                {
                    border12.Background = Brushes.Green;
                    border5.Background = Brushes.Green;
                }
                else
                {
                    border12.Background = Brushes.Red;
                    border5.Background = Brushes.Red;
                }
            }
        }

        private void image12_MouseLeave(object sender, MouseEventArgs e)
        {
           
            if (DownPosition < 10 || UpPosition < 10)
            {
                border12.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
                border5.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
            }
            else
            {
                if (colors[4])
                {
                    border12.Background = Brushes.Green;
                    border5.Background = Brushes.Green;
                }
                else
                {
                    border12.Background = Brushes.Red;
                    border5.Background = Brushes.Red;
                }
            }
        }

        private void image13_MouseEnter(object sender, MouseEventArgs e)
        {
          
            if (DownPosition < 12 || UpPosition < 12)
            {
                border13.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
                border6.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
            }
            else
            {
                if (colors[5])
                {
                    border13.Background = Brushes.Green;
                    border6.Background = Brushes.Green;
                }
                else
                {
                    border13.Background = Brushes.Red;
                    border6.Background = Brushes.Red;
                }
            }
        }

        private void image13_MouseLeave(object sender, MouseEventArgs e)
        {
        
            if (DownPosition < 12 || UpPosition < 12)
            {
                border13.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
                border6.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
            }
            else
            {
                if (colors[5])
                {
                    border13.Background = Brushes.Green;
                    border6.Background = Brushes.Green;
                }
                else
                {
                    border13.Background = Brushes.Red;
                    border6.Background = Brushes.Red;
                }
            }
        }

        private void image14_MouseEnter(object sender, MouseEventArgs e)
        {
           
            if (DownPosition < 14 || UpPosition < 14)
            {
                border14.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
                border7.Background = new LinearGradientBrush(Colors.SlateBlue, Colors.LightBlue, 90);
            }
            else
            {
                if (colors[6])
                {
                    border14.Background = Brushes.Green;
                    border7.Background = Brushes.Green;
                }
                else
                {
                    border14.Background = Brushes.Red;
                    border7.Background = Brushes.Red;
                }
            }
        }

        private void image14_MouseLeave(object sender, MouseEventArgs e)
        {
           
            if (DownPosition < 14 || UpPosition < 14)
            {
                border14.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
                border7.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
            }
            else
            {
                if (colors[6])
                {
                    border14.Background = Brushes.Green;
                    border7.Background = Brushes.Green;
                }
                else
                {
                    border14.Background = Brushes.Red;
                    border7.Background = Brushes.Red;
                }
            }
        }

        public string getStadoRadioButton()
        {
            string result = "";
            if(radioButton1.IsChecked == true)
                result = "mayor";
            if (radioButton2.IsChecked == true)
                result = "menor";
            if (radioButton3.IsChecked == true)
                result = "igual";
            return result;
        }
        //unoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
       
        private void image1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if(MyVerify && !client.GetGameStatus(user,"Luck") )
            {
                MessageBox.Show("you are played today, try again tomorrow");
                end = true;
                this.Close();
            }
            MyVerify = false;
                
            if (UpPosition == 1 && (DownPosition == 3 ||DownPosition == 1) )
            {
                string aux = luck.GetImage;
                
                PlayUp = luck.GetCard(aux);
                
                label1.Content = "";

                BitmapImage bi3 = new BitmapImage();
                bi3.BeginInit();
                bi3.UriSource = new Uri(aux, UriKind.Relative);
                bi3.EndInit();

                image1.Source = bi3;

                if (PlayDown != 0)
                {
                    string resultRadioButton = getStadoRadioButton();
                    char res = luck.Consult(PlayUp, PlayDown, resultRadioButton);

                    if (res == 's' )
                    {
                        label1.Content = "Congratulations you won";
                        label3.Content = luck.IncrementCoins(Convert.ToString(label3.Content));
                        colors[0] = true;                        
                    }
                    else
                    {
                        if (res == 'n' || res == 'o' )
                        {
                            label1.Content = "I'm sorry you lost";
                            label3.Content = luck.DecreaseCoins(Convert.ToString(label3.Content));
                            colors[0] = false;
                        }
                        else
                        {
                            onlyOneMessage = true;
                            MessageBox.Show("Congratulations you won 1000 ");
                            this.Close();
                        }
                    }
                    PlayDown = 0;
                    PlayUp = 0;
                }/////////

                

                UpPosition = UpPosition + 2;
                
            }
        }

        private void image8_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (MyVerify && !client.GetGameStatus(user, "Luck"))
            {
                MessageBox.Show("you are played today, try again tomorrow");
                end = true;
                this.Close();
                
            }
            MyVerify = false;
                
            if (DownPosition == 1 && (UpPosition == 3 || UpPosition == 1))
            {
                string aux = luck.GetImage;
                label1.Content = "";
                PlayDown = luck.GetCard(aux);/////////


                BitmapImage bi3 = new BitmapImage();
                bi3.BeginInit();
                bi3.UriSource = new Uri(aux, UriKind.Relative);
                bi3.EndInit();
                image8.Source = bi3;

                if (PlayUp != 0)
                {
                    string resultRadioButton = getStadoRadioButton();
                    char res = luck.Consult(PlayDown, PlayUp, resultRadioButton);

                    if (res == 's')
                    {
                        label1.Content = "Congratulations you won";
                        label3.Content = luck.IncrementCoins(Convert.ToString(label3.Content));
                        colors[0] = true;
                    }
                    else
                    {
                        if (res == 'n' || res == 'o')
                        {
                            label1.Content = "I'm sorry you lost";
                            label3.Content = luck.DecreaseCoins(Convert.ToString(label3.Content));
                            colors[0] = false;
                        }
                        else
                        {
                            onlyOneMessage = true;
                            MessageBox.Show("Congratulations you won 1000");
                            this.Close();
                        }
                    }
                    PlayDown = 0;
                    PlayUp = 0;
                }

                DownPosition = DownPosition + 2;
                
            }
            
        }
        //dosssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
        private void image2_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (UpPosition == 3 && (DownPosition == 3 || DownPosition == 5))
            {
                string auxiliary = luck.GetImage;

                PlayUp = luck.GetCard(auxiliary);/////////
                label1.Content = "";

                BitmapImage bitMap = new BitmapImage();
                bitMap.BeginInit();
                bitMap.UriSource = new Uri(auxiliary, UriKind.Relative);
                bitMap.EndInit();
                
                image2.Source = bitMap;

                if (PlayDown != 0)
                {
                    string resultRadioButton = getStadoRadioButton();
                    char result = luck.Consult(PlayUp, PlayDown, resultRadioButton);

                    if (result == 's')
                    {
                        label1.Content = "Congratulations you won";
                        label3.Content = luck.IncrementCoins(Convert.ToString(label3.Content));
                        colors[1] = true; 
                    }
                    else
                    {
                        if (result == 'n' || result == 'o')
                        {
                            label1.Content = "I'm sorry you lost";
                            label3.Content = luck.DecreaseCoins(Convert.ToString(label3.Content));
                            colors[1] = false;
                        }
                        else
                        {
                            onlyOneMessage = true;
                            MessageBox.Show("Congratulations you won 1000");
                            this.Close();
                        }
                    }
                    PlayDown = 0;
                    PlayUp = 0;
                }/////////

                
                UpPosition = UpPosition + 2;
               
            }
            else
            {
                if(UpPosition <= 3)
                    MessageBox.Show("you should start at the left or open the other letter");
            }
        }

        private void image9_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (DownPosition == 3 && (UpPosition == 3 || UpPosition == 5))
            {
                string auxiliary = luck.GetImage;

                PlayDown = luck.GetCard(auxiliary);/////////
                label1.Content = "";


                BitmapImage bitMap = new BitmapImage();
                bitMap.BeginInit();
                bitMap.UriSource = new Uri(auxiliary, UriKind.Relative);
                bitMap.EndInit();
                
                image9.Source = bitMap;

                if (PlayUp != 0)
                {
                    string resultRadioButton = getStadoRadioButton();
                    char result = luck.Consult(PlayDown, PlayUp, resultRadioButton);

                    if (result == 's')
                    {
                        label1.Content = "Congratulations you won";
                        label3.Content = luck.IncrementCoins(Convert.ToString(label3.Content));
                        colors[1] = true; 
                    }
                    else
                    {
                        if (result == 'n' || result == 'o')
                        {
                            label1.Content = "I'm sorry you lost";
                            label3.Content = luck.DecreaseCoins(Convert.ToString(label3.Content));
                            colors[1] = false;
                        }
                        else
                        {
                            onlyOneMessage = true;
                            MessageBox.Show("Congratulations you won 1000");
                            this.Close();
                        }
                    }
                    PlayDown = 0;
                    PlayUp = 0;
                }

                DownPosition = DownPosition + 2;
                
            }
            else
            {
                if(DownPosition <= 3)
                    MessageBox.Show("you should start at the left or open the other letter");
            }
        }
        //tresssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
        private void image3_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (UpPosition == 5 && (DownPosition == 5 || DownPosition == 7))
            {
                string auxiliary = luck.GetImage;

                PlayUp = luck.GetCard(auxiliary);/////////
                label1.Content = "";


                BitmapImage bitMap = new BitmapImage();
                bitMap.BeginInit();
                bitMap.UriSource = new Uri(auxiliary, UriKind.Relative);
                bitMap.EndInit();
                
                image3.Source = bitMap;

                if (PlayDown != 0)
                {
                    string resultRadioButton = getStadoRadioButton();
                    char result = luck.Consult(PlayUp, PlayDown, resultRadioButton);

                    if (result == 's')
                    {
                        label1.Content = "Congratulations you won";
                        label3.Content = luck.IncrementCoins(Convert.ToString(label3.Content));
                        colors[2] = true; 
                    }
                    else
                    {
                        if (result == 'n' || result == 'o')
                        {
                            label1.Content = "I'm sorry you lost";
                            label3.Content = luck.DecreaseCoins(Convert.ToString(label3.Content));
                            colors[2] = false;
                        }
                        else
                        {
                            onlyOneMessage = true;
                            MessageBox.Show("Congratulations you won 1000");
                            this.Close();
                        }
                    }
                    PlayDown = 0;
                    PlayUp = 0;
                }/////

                UpPosition = UpPosition + 2;
               
            }
            else
            {
                if (UpPosition <= 5)
                    MessageBox.Show("you should start at the left or open the other letter");
            }
        }

        private void image10_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (DownPosition == 5 && (UpPosition == 5 || UpPosition == 7))
            {
                string aux = luck.GetImage;

                PlayDown = luck.GetCard(aux);/////////
                label1.Content = "";


                BitmapImage bi3 = new BitmapImage();
                bi3.BeginInit();
                bi3.UriSource = new Uri(aux, UriKind.Relative);
                bi3.EndInit();
                
                image10.Source = bi3;

                if (PlayUp != 0)
                {
                    string resultRadioButton = getStadoRadioButton();
                    char res = luck.Consult(PlayDown, PlayUp, resultRadioButton);

                    if (res == 's')
                    {
                        label1.Content = "Congratulations you won";
                        label3.Content = luck.IncrementCoins(Convert.ToString(label3.Content));
                        colors[2] = true; 
                    }
                    else
                    {
                        if (res == 'n' || res == 'o')
                        {
                            label1.Content = "I'm sorry you lost";
                            label3.Content = luck.DecreaseCoins(Convert.ToString(label3.Content));
                            colors[2] = false;
                        }
                        else
                        {
                            onlyOneMessage = true;
                            MessageBox.Show("Congratulations you won 1000");
                            this.Close();
                        }
                    }
                    PlayDown = 0;
                    PlayUp = 0;
                }/////////

                DownPosition = DownPosition + 2;
                //actual = 1;

            }
            else
            {
                if (DownPosition <= 5)
                    MessageBox.Show("you should start at the left or open the other letter");
            }
        }
        //cuatrooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
        private void image4_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (UpPosition == 7 && (DownPosition == 7 || DownPosition == 9))
            {
                string aux = luck.GetImage;

                PlayUp = luck.GetCard(aux);/////////
                label1.Content = "";
                BitmapImage bi3 = new BitmapImage();
                bi3.BeginInit();
                bi3.UriSource = new Uri(aux, UriKind.Relative);
                bi3.EndInit();
                
                image4.Source = bi3;

                if (PlayDown != 0)
                {
                    string resultRadioButton = getStadoRadioButton();
                    char res = luck.Consult(PlayUp, PlayDown, resultRadioButton);

                    if (res == 's')
                    {
                        label1.Content = "Congratulations you won";
                        label3.Content = luck.IncrementCoins(Convert.ToString(label3.Content));
                        colors[3] = true; 
                    }
                    else
                    {
                        if (res == 'n' || res == 'o')
                        {
                            label1.Content = "I'm sorry you lost";
                            label3.Content = luck.DecreaseCoins(Convert.ToString(label3.Content));
                            colors[3] = false;
                        }
                        else
                        {
                            onlyOneMessage = true;
                            MessageBox.Show("Congratulations you won 1000");
                            this.Close();
                        }
                    }
                    PlayDown = 0;
                    PlayUp = 0;
                }/////

                
                UpPosition = UpPosition + 2;
                //actual = 1;

            }
            else
            {
                if (UpPosition <= 7)
                    MessageBox.Show("you should start at the left or open the other letter");
            }
        }

        private void image11_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (DownPosition == 7 && (UpPosition == 9 || UpPosition == 7))
            {
                string aux = luck.GetImage;

                PlayDown = luck.GetCard(aux);/////////
                label1.Content = "";

                BitmapImage bi3 = new BitmapImage();
                bi3.BeginInit();
                bi3.UriSource = new Uri(aux, UriKind.Relative);
                bi3.EndInit();
                
                image11.Source = bi3;

                if (PlayUp != 0)
                {
                    string resultRadioButton = getStadoRadioButton();
                    char res = luck.Consult(PlayDown, PlayUp, resultRadioButton);

                    if (res == 's')
                    {
                        label1.Content = "Congratulations you won";
                        label3.Content = luck.IncrementCoins(Convert.ToString(label3.Content));
                        colors[3] = true; 
                    }
                    else
                    {
                        if (res == 'n' || res == 'o')
                        {
                            label1.Content = "I'm sorry you lost";
                            label3.Content = luck.DecreaseCoins(Convert.ToString(label3.Content));
                            colors[3] = false;
                        }
                        else
                        {
                            onlyOneMessage = true;
                            MessageBox.Show("Congratulations you won 1000");
                            this.Close();
                        }
                    }
                    PlayDown = 0;
                    PlayUp = 0;
                }/////////

                DownPosition = DownPosition + 2;
               // actual = 1;

            }
            else
            {
                if (DownPosition <= 7)
                    MessageBox.Show("you should start at the left or open the other letter");
            }
        }
        //cincooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
        private void image5_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (UpPosition == 9 && (DownPosition == 11 || DownPosition == 9))
            {
                string aux = luck.GetImage;

                PlayUp = luck.GetCard(aux);/////////
                label1.Content = "";

                BitmapImage bi3 = new BitmapImage();
                bi3.BeginInit();
                bi3.UriSource = new Uri(aux, UriKind.Relative);
                bi3.EndInit();
                
                image5.Source = bi3;

                if (PlayDown != 0)
                {
                    string resultRadioButton = getStadoRadioButton();
                    char res = luck.Consult(PlayUp, PlayDown, resultRadioButton);

                    if (res == 's')
                    {
                        label1.Content = "Congratulations you won";
                        label3.Content = luck.IncrementCoins(Convert.ToString(label3.Content));
                        colors[4] = true; 
                    }
                    else
                    {
                        if (res == 'n' || res == 'o')
                        {
                            label1.Content = "I'm sorry you lost";
                            label3.Content = luck.DecreaseCoins(Convert.ToString(label3.Content));
                            colors[4] = false;
                        }
                        else
                        {
                            onlyOneMessage = true;
                            MessageBox.Show("Congratulations you won 1000");
                            this.Close();
                        }
                    }
                    PlayDown = 0;
                    PlayUp = 0;
                }/////

                UpPosition = UpPosition + 2;
               // actual = 1;

            }
            else
            {
                if (UpPosition <= 9)
                    MessageBox.Show("you should start at the left or open the other letter");
            }
        }

        private void image12_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (DownPosition == 9 && (UpPosition == 9 || UpPosition == 11))
            {
                string aux = luck.GetImage;

                PlayDown = luck.GetCard(aux);/////////
                label1.Content = "";
                BitmapImage bi3 = new BitmapImage();
                bi3.BeginInit();
                bi3.UriSource = new Uri(aux, UriKind.Relative);
                bi3.EndInit();
                
                image12.Source = bi3;

                if (PlayUp != 0)
                {
                    string resultRadioButton = getStadoRadioButton();
                    char res = luck.Consult(PlayDown, PlayUp, resultRadioButton);

                    if (res == 's')
                    {
                        label1.Content = "Congratulations you won";
                        label3.Content = luck.IncrementCoins(Convert.ToString(label3.Content));
                        colors[4] = true; 
                    }
                    else
                    {
                        if (res == 'n' || res == 'o')
                        {
                            label1.Content = "I'm sorry you lost";
                            label3.Content = luck.DecreaseCoins(Convert.ToString(label3.Content));
                            colors[4] = false;
                        }
                        else
                        {
                            onlyOneMessage = true;
                            MessageBox.Show("Congratulations you won 1000");
                            this.Close();
                        }
                    }
                    PlayDown = 0;
                    PlayUp = 0;
                }/////////

                
                DownPosition = DownPosition + 2;
                //actual = 1;

            }
            else
            {
                if (DownPosition <= 9)
                    MessageBox.Show("you should start at the left or open the other letter");
            }
        }
        //poiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
        private void image6_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (UpPosition == 11 && (DownPosition == 11 || DownPosition == 13))
            {
                string aux = luck.GetImage;

                PlayUp = luck.GetCard(aux);/////////
                label1.Content = "";

                BitmapImage bi3 = new BitmapImage();
                bi3.BeginInit();
                bi3.UriSource = new Uri(aux, UriKind.Relative);
                bi3.EndInit();
                
                image6.Source = bi3;

                if (PlayDown != 0)
                {
                    string resultRadioButton = getStadoRadioButton();
                    char res = luck.Consult(PlayUp, PlayDown, resultRadioButton);

                    if (res == 's')
                    {
                        label1.Content = "Congratulations you won";
                        label3.Content = luck.IncrementCoins(Convert.ToString(label3.Content));
                        colors[5] = true; 
                    }
                    else
                    {
                        if (res == 'n' || res == 'o')
                        {
                            label1.Content = "I'm sorry you lost";
                            label3.Content = luck.DecreaseCoins(Convert.ToString(label3.Content));
                            colors[5] = false;
                        }
                        else
                        {
                            onlyOneMessage = true;
                            MessageBox.Show("Congratulations you won 1000");
                            this.Close();
                        }
                    }
                    PlayDown = 0;
                    PlayUp = 0;
                }/////

                UpPosition = UpPosition + 2;
               // actual = 1;

            }
            else
            {
                if (UpPosition <= 11)
                    MessageBox.Show("you should start at the left or open the other letter");
            }
        }

        private void image13_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (DownPosition == 11 && (UpPosition == 13 || UpPosition == 11))
            {
                string aux = luck.GetImage;

                PlayDown = luck.GetCard(aux);/////////
                label1.Content = "";

                BitmapImage bi3 = new BitmapImage();
                bi3.BeginInit();
                bi3.UriSource = new Uri(aux, UriKind.Relative);
                bi3.EndInit();
                
                image13.Source = bi3;

                if (PlayUp != 0)
                {
                    string resultRadioButton = getStadoRadioButton();
                    char res = luck.Consult(PlayDown, PlayUp, resultRadioButton);

                    if (res == 's')
                    {
                        label1.Content = "Congratulations you won";
                        label3.Content = luck.IncrementCoins(Convert.ToString(label3.Content));
                        colors[5] = true; 
                    }
                    else
                    {
                        if (res == 'n' || res == 'o')
                        {
                            label1.Content = "I'm sorry you lost";
                            label3.Content = luck.DecreaseCoins(Convert.ToString(label3.Content));
                            colors[5] = false;
                        }
                        else
                        {
                            onlyOneMessage = true;
                            MessageBox.Show("Congratulations you won 1000");
                            this.Close();
                        }
                    }
                    PlayDown = 0;
                    PlayUp = 0;
                }/////////

                DownPosition = DownPosition + 2;
                //actual = 1;

            }
            else
            {
                if (DownPosition <= 11)
                    MessageBox.Show("you should start at the left or open the other letter");
            }
        }
        //juhhhhhhhggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg
        private void image7_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (UpPosition == 13 && (DownPosition == 15 || DownPosition == 13))
            {
                string aux = luck.GetImage;

                PlayUp = luck.GetCard(aux);/////////
                label1.Content = "";
                BitmapImage bi3 = new BitmapImage();
                bi3.BeginInit();
                bi3.UriSource = new Uri(aux, UriKind.Relative);
                bi3.EndInit();
                
                image7.Source = bi3;

                if (PlayDown != 0)
                {
                    string resultRadioButton = getStadoRadioButton();
                    char res = luck.Consult(PlayUp, PlayDown, resultRadioButton);

                    if (res == 's')
                    {
                        label1.Content = "Congratulations you won";
                        label3.Content = luck.IncrementCoins(Convert.ToString(label3.Content));
                        colors[6] = true; 
                    }
                    else
                    {
                        if (res == 'n' || res == 'o')
                        {
                            label1.Content = "I'm sorry you lost";
                            label3.Content = luck.DecreaseCoins(Convert.ToString(label3.Content));
                            colors[6] = false;
                        }
                        else
                        {
                            onlyOneMessage = true;
                            end = true;
                            MessageBox.Show("Congratulations you won 1000");
                            client.SetGameStatus(user, "Luck");
                            user.Chips = user.Chips+ Convert.ToInt32(label3.Content);
                            client.Send("14 " + user.Name + " " + user.Chips);
                            client.Receive();
                            pol = true;
                            this.Close();
                            
                        }
                    }
                    
                }

                
                UpPosition = UpPosition + 2;
               
            }
            else
            {
                if (UpPosition <= 13)
                    MessageBox.Show("you should start at the left or open the other letter");
            }
            if (PlayDown != 0 && PlayUp != 0)
            {
                end = true;
                if (onlyOneMessage==false)
                     MessageBox.Show("Chips won " + label3.Content);
                client.SetGameStatus(user, "Luck");
                user.Chips = user.Chips + Convert.ToInt32(label3.Content);
                client.Send("14 " + user.Name + " " + user.Chips);
                client.Receive();
                pol = true;
                this.Close();
                
            }
        }

        private void image14_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (DownPosition == 13 && (UpPosition == 13 || UpPosition == 15))
            {
                string aux = luck.GetImage;

                PlayDown = luck.GetCard(aux);
                label1.Content = "";

                BitmapImage bi3 = new BitmapImage();
                bi3.BeginInit();
                bi3.UriSource = new Uri(aux, UriKind.Relative);
                bi3.EndInit();
                
                image14.Source = bi3;

                if (PlayUp != 0)
                {
                    string resultRadioButton = getStadoRadioButton();
                    char res = luck.Consult(PlayDown, PlayUp, resultRadioButton);
                    colors[6] = true; 

                    if (res == 's')
                    {
                        label1.Content = "Congratulations you won";
                        label3.Content = luck.IncrementCoins(Convert.ToString(label3.Content));
                        colors[6] = true; 
                    }
                    else
                    {
                        if (res == 'n' || res == 'o')
                        {
                            label1.Content = "I'm sorry you lost";
                            label3.Content = luck.DecreaseCoins(Convert.ToString(label3.Content));
                            colors[6] = false;
                        }
                        else
                        {
                            onlyOneMessage = true;
                            end = true;
                            MessageBox.Show("Congratulations you won 1000");
                            client.SetGameStatus(user, "Luck");
                            user.Chips = user.Chips + Convert.ToInt32(label3.Content);
                            client.Send("14 " + user.Name + " " + user.Chips);
                            client.Receive();
                            pol = true;
                            this.Close();
                           
                        }
                    }
                }

                DownPosition = DownPosition + 2;
               // actual = 1;

            }
            else
            {
                if (DownPosition <= 13)
                    MessageBox.Show("you should start at the left or open the other letter");
            }
            if (PlayDown != 0 && PlayUp != 0)
            {
                end = true;
                if(onlyOneMessage==false)
                       MessageBox.Show("Chips won " + label3.Content);
                client.SetGameStatus(user, "Luck");
                user.Chips = user.Chips + Convert.ToInt32(label3.Content);
                client.Send("14 " + user.Name + " " + user.Chips);
                client.Receive();
                pol = true;
                this.Close();
                
            }
                
        }

        bool pol = false;
        private void Window_Closed(object sender, EventArgs e)
        {
            if(pol == false && !onlyOneMessage)
                MessageBox.Show("Chips won " + label3.Content);
           
        }

        private void Window_Closing(object sender, CancelEventArgs e)
        {
            if (!Banned)
            {
                if (!end && !onlyOneMessage)
                {
                    MessageBox.Show("chips won " + Convert.ToString(label3.Content));
                    user.Chips = user.Chips + Convert.ToInt32(label3.Content);
                    client.SetGameStatus(user, "Luck");
                    client.Send("14 " + user.Name + " " + user.Chips);
                    client.Receive();
                }
            }
        }









        public void Ban()
        {
            Banned = true;
            Close();
        }

        private void image6_ImageFailed(object sender, ExceptionRoutedEventArgs e)
        {

        }
    }
}
